Hệ thống quản lý phòng khám trực tuyến bằng PHP
1 <?php if(!defined('datalist_date_separator')) die('datalist.php not included!');
2
3 class Combo{
4 // The Combo class renders a drop down combo
5 // filled with elements in an array ListItem[]
6 // and associates each element with data from
7 // an array ListData[], and optionally selects
8 // one of the items.
9
10 var $ListItem, // array of items in the combo
11 $ListData, // array of items data values
12 $Class,
13 $SelectedClass,
14 $Style,
15 $SelectName,
16 $SelectID,
17 $SelectedData,
18 $SelectedText,
19 $MatchText, // will store the text value of the matching item.
20
21 $ListType, // 0: drop down combo, 1: list box, 2: radio buttons, 3: multi-selection list box
22 $ListBoxHeight, // if ListType=1, this is the height of the list box
23 $MultipleSeparator, // if ListType=3, specify the list separator here (default ,)
24 $RadiosPerLine, // if ListType=2, this is the number of options per line
25
26 $AllowNull,
27 $ApplySelect2, // boolean, default is true
28
29 $HTML; // the resulting output HTML code to use
30
31 function __construct(){ // PHP 7 compatibility
32 $this->Combo();
33 }
34
35 function Combo(){ // Constructor function
36 $this->Class = 'form-control';
37 $this->SelectedClass = 'active';
38 $this->HTML = '';
39 $this->ListType = 0;
40 $this->ListBoxHeight = 10;
41 $this->MultipleSeparator = ', ';
42 $this->RadiosPerLine = 1;
43 $this->AllowNull = true;
44 $this->ApplySelect2 = true;
45 }
46
47 function Render(){
48 global $Translation;
49 $this->HTML = '';
50 $ArrayCount = count($this->ListItem);
51
52 if($ArrayCount > count($this->ListData)){
53 $this->HTML .= 'Invalid Class Definition';
54 return 0;
55 }
56
57 if(!$this->SelectID) $this->SelectID=str_replace(array('[', ']'), '_', $this->SelectName);
58
59 if($this->ListType != 2){
60 if($this->ApplySelect2){
61 $this->HTML .= "<select style=\"width: 100%;\" name=\"$this->SelectName".($this->ListType==3 ? '[]' : '')."\" id=\"$this->SelectID\"".($this->ListType==1 ? ' size="'.($this->ListBoxHeight < $ArrayCount ? $this->ListBoxHeight : ($ArrayCount + ($this->AllowNull ? 1 : 0))).'"' : '').($this->ListType==3 ? ' multiple' : '').'>';
62 }else{
63 $this->HTML .= "<select name=\"$this->SelectName".($this->ListType==3 ? '[]' : '')."\" id=\"$this->SelectID\" class=\"$this->Class\" style=\"$this->Style\"".($this->ListType==1 ? ' size="'.($this->ListBoxHeight < $ArrayCount ? $this->ListBoxHeight : ($ArrayCount + ($this->AllowNull ? 1 : 0))).'"' : '').($this->ListType==3 ? ' multiple' : '').'>';
64 }
65
66 $this->HTML .= ($this->AllowNull ? "\n\t<option value=\"\"> </option>" : '');
67
68 if($this->ListType==3) $arrSelectedData=explode($this->MultipleSeparator, $this->SelectedData);
69 if($this->ListType==3) $arrSelectedText=explode($this->MultipleSeparator, $this->SelectedText);
70 for($i = 0; $i < $ArrayCount; $i++){
71 if($this->ListType==3){
72 if(in_array($this->ListData[$i], $arrSelectedData)){
73 $sel = "selected class=\"$this->SelectedClass\"";
74 $this->MatchText.=$this->ListItem[$i].$this->MultipleSeparator;
75 }else{
76 $sel = '';
77 }
78 }else{
79 if($this->SelectedData == $this->ListData[$i] || ($this->SelectedText == $this->ListItem[$i] && $this->SelectedText)){
80 $sel = "selected class=\"$this->SelectedClass\"";
81 $this->MatchText=$this->ListItem[$i];
82 $this->SelectedData=$this->ListData[$i];
83 $this->SelectedText=$this->ListItem[$i];
84 }else{
85 $sel = '';
86 }
87 }
88
89 $this->HTML .= "\n\t<option value=\"" . $this->ListData[$i] . "\" $sel>" . stripslashes(strip_tags($this->ListItem[$i])) . "</option>";
90 }
91 $this->HTML .= '</select>';
92 if($this->ApplySelect2){
93 $this->HTML .= '<script>jQuery(function(){ jQuery("#' . $this->SelectID . '").addClass(\'option_list\').select2({ minimumResultsForSearch: 15, width: \'90%\' }); })</script>';
94 }
95 if($this->ListType == 3 && strlen($this->MatchText)>0) $this->MatchText=substr($this->MatchText, 0, -1 * strlen($this->MultipleSeparator));
96 }else{
97 global $Translation;
98 $separator = ' ';
99
100 $j=0;
101 $this->HTML .= '<div>';
102 if($this->AllowNull){
103 $this->HTML .= "<input id=\"$this->SelectName$j\" type=\"radio\" name=\"$this->SelectName\" value=\"\" ".($this->SelectedData==''?'checked':'')."> <label for=\"$this->SelectName$j\">{$Translation['none']}</label>";
104 $this->HTML .= ($this->RadiosPerLine==1 ? '<br>' : $separator);
105 $shift=2;
106 }else{
107 $shift=1;
108 }
109 for($i = 0; $i < $ArrayCount; $i++){
110 $j++;
111 if($this->SelectedData == $this->ListData[$i] || ($this->SelectedText == $this->ListItem[$i] && $this->SelectedText)){
112 $sel = "checked class=\"$this->SelectedClass\"";
113 $this->MatchText=$this->ListItem[$i];
114 $this->SelectedData=$this->ListData[$i];
115 $this->SelectedText=$this->ListItem[$i];
116 }else{
117 $sel = '';
118 }
119
120 $this->HTML .= "<input id=\"$this->SelectName$j\" type=\"radio\" name=\"$this->SelectName\" value=\"{$this->ListData[$i]}\" $sel> <label for=\"$this->SelectName$j\">".str_replace('&', '&', html_attr(stripslashes($this->ListItem[$i])))."</label>";
121 if(($i+$shift)%$this->RadiosPerLine){
122 $this->HTML .= $separator;
123 }else{
124 $this->HTML .= '<br>';
125 }
126 }
127 $this->HTML .= '</div>';
128 }
129
130 return 1;
131 }
132 }